@extends('admin.layouts.master')
@section('content')
    <link rel="stylesheet"
          href="{{asset('static/bootstrap/css/bootstrap.min.css')}}">
    <div class="col-md-12">
        <!-- 自定义内容区域 -->
        <div class="panel panel-default">
            <div class="panel-heading">添加角色</div>
            <div class="panel-body">
                <form class="form-horizontal" action="{{url('admin/admin_role/store')}}"  method="post" >
                    {{csrf_field()}}
                    <div class="form-group">
                        <label class="col-sm-2 control-label">角色名称：</label>

                        <div class="col-sm-5">

                            <input type="text" name="name" placeholder="%admin%">

                        </div>

                    </div>
                    <div class="form-group">
                        <label for="age" class="col-sm-2 control-label">角色标识：</label>

                        <div class="col-sm-5">
                            <input type="text" name="display_name" placeholder="%超级管理员%">
                        </div>

                    </div>

                    <div class="form-group">
                        <label class="col-sm-2 control-label">角色描述：</label>

                        <div class="col-sm-5">

                            <textarea name="description" id="" cols="30" rows="10"></textarea>

                        </div>

                    </div>

                    <div class="form-group">
                        <label class="col-sm-2 control-label">权限:</label>

                        <div class="col-sm-5">
                            @foreach($permissions as $permission)
                                @if($permission->parent_id == 0)
                                    <p style="margin:0;font-size: 14px; color: #2ca02c;">
                                        <label>
                                          <input type="checkbox"  onclick="big()" name="role_id[]"
                                                 value="{{$permission->id}}" >{{$permission->name}}
                                        </label>
                                    </p>
                                @else
                                    <label>
                                        <input class="{{$permission->parent_id}}" type="checkbox"  onclick="small()" name="role_id[]"
                                               value="{{$permission->id}}">{{$permission->name}}
                                    </label>
                                @endif
                            @endforeach

                        </div>

                    </div>
                    <div class="form-group">
                        <div class="col-sm-offset-2 col-sm-10">
                            <button type="submit" id="addpermission" class="btn btn-primary">提交</button>
                            <button type="submit" onclick="history.go(-1)" class="back btn btn-primary">返回</button>

                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <!-- jQuery 文件 -->
    <script src="{{asset('static/jquery/jquery.min.js')}}"></script>
    <!-- Bootstrap JavaScript 文件 -->
    <script src="{{asset('static/bootstrap/js/bootstrap.min.js')}}"></script>
@endsection
@section('js')
    <script type="text/javascript">
        $(function () {
            $('p').find('input').each(function () {
                $(this).click(function () {
                    x = $(this).val();
                    if ($(this).attr('checked')) {
                        $('.'+x).attr('checked', 'true');
                    } else {
                        $('.'+x).removeAttr('checked');
                    }
                })
            })
        });
    </script>
@endsection
